/****************创建服务器server.js****************************/
const express = require('express')
const cors =require('cors')
const app = express()
const port = 8080
app.listen(port,()=>{
	console.log('成功监听端口'+port)
})

app.use(cors())



//添加中间件
app.use(express.urlencoded({
	extended:true
}))
//静态托管
app.use(express.static('./public'))


//引入热门风景路由器并添加前缀
const sceneryRouter = require('./router/scenery.js')
app.use('/v1/scenery',sceneryRouter)

//引入旅游攻略路由器
const methodRouter = require('./router/travel_method.js')
app.use('/v1/method',methodRouter)

//引入舟山必玩路由器
const activityRouter = require('./router/activity.js')
app.use('/v1/activity',activityRouter)

//引入舟山海味路由器
const foodRouter = require('./router/food.js')
app.use('/v1/food',foodRouter )

//引入酒店民宿路由器
const hotelRouter = require('./router/hotel.js')
app.use('/v1/hotel',hotelRouter)

//引入用户路由器
const userRouter = require('./router/user.js')
app.use('/v1/user',userRouter)

//引入导游路由器
const guideRouter = require('./router/guide.js')
app.use('/v1/guide',guideRouter)

//引入交通信息的路由器
const transportRouter = require('./router/transport.js')
app.use('/v1/transport',transportRouter)

//添加错误处理中间件 拦截所有路由器的错误
app.use((err,req,res,next)=>{
	console.log(err)
	res.send({code:500,msg:'服务器端错误'})
})